A r t i c l e s
Navigation

Note: This site is
a bit older, personal views
may have changed.

M a i n P a g e

D i r e c t o r y

PHP vs PSP Object Orientation



Discussing the differences between PSP OO and PHP OO. 
  PSP: Pascal Server Pages 
  PHP: Pre Hypertext Processor


Below are some small comparision examples. Generally, it's best to compare real world larger examples.. but this gives you some idea.
PHP code (#1): if (isset($some1)) { echo "This showing text."; } Pascal CGI code (#1): if some1 <> nil then writeln('This showing text.'); PHP with OO (#1): if ($something->dostuff) { echo "This some text."; } Pascal CGI with OO (#1): if Something.DoStuff then WriteLn('This some text.');
PHP OO snippet (#2): <?php class coolclass { private $some1 = "hello"; public function getVar() { return $some1; } } // and now our program code block $obj = new coolclass(); echo $obj->getVar(); ?> Note: php requires you use brackets to launch getVar, and you can initialize the "hello" string inside the class interface (which can crowd the class interface up sometimes and is not always recommended). On the other hand, in FPC/Delphi you initialize the string variable in the constructor instead of in the class declaration, and brackets do not have to be used to launch a function.
Pascal CGI OO snippet (#2): type TCoolClass = class private some1: string; public function GetVar: string; end; constructor TCoolClass.Create; begin some1:= 'hello'; end; function TCoolClass.GetVar: string; begin result:= some1; end; var Obj1: TCoolClass; // and now our program code block begin Obj1:= TCoolClass.create; writeln(Obj1.GetVar); end.
Other differences with Pascal CGI: -all source code comments stay on the developer's computer. No source code or comments get uploaded to the server. -only the program gets uploaded to the server -if someone hacks into your server, all they see is a bunch of binary files and no source code. With php, once they get in they see all passwords,source code, and source code comments. -uploads will take longer, however one can use programs with ini files of his own, and HTML files which he can change on the fly, without recompiling a program and uploading. -For serious web apps, the amount of extra time it takes to upload a program versus the source code is not a big issue. Uploading your source code may be faster for you, but the customer gets the interpretter hit and you have your source code wide open to hackers. -The pascal CGI code will be re-usable in your Delphi, Freepascal, Lazarus applications. PHP code is not re-usable.. unless you are using something like a PHP compiler of some sort to build programs. Or you honestly use PHP at the command prompt for shell scripts, or you actually create and use php GTK apps. -Re-using existing offline software code that you programmed months or years ago with Pascal is possible. Whereas with PHP you have to use code that's pretty much for the web only. If there is a php compiler that is viable in the future, and people are actually using PHP to create offline software applications, this could change. Then it will be only a matter of taste, language preference, community attitude, etc.


About
This site is about programming and other things.
_ _ _